<HTML>
<HEAD>
<TITLE>JavaScript Source Code 3000:  Password Protection:  Virgenere Encryption</TITLE>
<META HTTP-EQUIV="JavaScript Source Code 3000" CONTENT = "no-cache">
<META NAME="date" CONTENT="2000-09-09">
<META NAME="channel" CONTENT="Web Developer">
<META NAME="author" CONTENT="Francisco Ryan Tolmasky (iopossum@mailcity.com)">
<META NAME="section" CONTENT="Password Protection">
<META NAME="description" CONTENT="A fine example of the classic virgenere script and is nearly impossible to decode, even when using frequency analysis.  This script is also entertaining since you can actually see the encryption taking place.">

<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Francisco Ryan Tolmasky (iopossum@mailcity.com) -->
<!-- Web Site:  http://iopossum.tripod.com -->




<!-- Begin
var TID = 0;
var longer = 0;
var thirdwrite = "";
var alphabet = new Array("0@","1#","2$","3%","4^","5&","6*","7 = ","8-","9+","Aa","Bb","Cc","Dd","Ee","Ff","Gg","Hh","Ii","Jj","Kk","Ll","Mm","Nn","Oo","Pp","Qq","Rr","Ss","Tt","Uu","Vv","Ww","Xx","Yy","Zz");
function preTime(coco, uinput, question) {
longer = coco.length - 1;
placement = 0;
ref = 0 ;
secondWrite = "";
firstWrite = "";
thirdWrite = "";
code1(coco, uinput, longer, question);
}
function findshift(letter) {
for (i = 0; i < 36; i++) {
if ((alphabet[i].substring(0,1) == letter) || (alphabet[i].substring(1,2) == letter)) {
if (alphabet[i].substring(0,1) == letter) {
x = 0;
}
if (alphabet[i].substring(1,2) == letter) {
x = 1;
}
return i;
      }
   }
}
function check(letter) {
bill = "no";
for (i = 0; i < 36; i++) {
if ((alphabet[i].substring(0,1) == letter) || (alphabet[i].substring(1,2) == letter)) {
bill = "yes";
   }
}
if (bill == "yes") {
return true;
}
else {
return false;
   }
}
function fixoffset(takin) {
if (takin > 35) {
return (takin - 36);
}
else {
return takin;
   }
}
function code1(inval1,inval2,inval3,sage) {
if (check(inval2.charAt(placement))) {
if (check(inval1.charAt(ref))) {
if (sage == 0) { 
shift = findshift(inval1.charAt(ref));
}
if (sage == 1) { 
shift = 36 - findshift(inval1.charAt(ref));
   }
}
else {
shift = 0;
}
orig = findshift(inval2.charAt(placement));
firstWrite = firstWrite+alphabet[fixoffset(orig+shift)].charAt(x);
}
else {
firstWrite = firstWrite+inval2.charAt(placement);
}
secondWrite = inval2.substring(placement+1,inval2.length+1);
thirdWrite = firstWrite+secondWrite;
document.inputo.written.value = thirdWrite;
placement++;
if (ref == inval3) {
ref = 0
}
else {
ref++;
}
if (placement == (inval2.length)) {
window.clearTimeout(TID);
return false;
}
one = inval1;
two = inval2;
three = inval3;
goer = sage;
TID = window.setTimeout("code1(one, two, three, goer)", 0);
}
//  End -->
</script>
</HEAD>

<BODY BGCOLOR=#ffffff vlink=#0000ff>

<BR>
<center>
<table width=600 cellpadding=0 cellspacing=10>
<tr>
<td width=468 align=center>

    
    
</td>
<td width=120 align=center>
    
</td>
</tr>
</table>
<BR>
<BR>
<basefont size=3>
<FONT SIZE="+2" FACE="Helvetica,Arial">
<A HREF="../index.htm" /" TARGET="_top"><FONT COLOR="#0000FF"><b>Home</b></font></A>
<img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}">
<A HREF="index.htm" /passwords/"><font color="#FF0000"><b>Password Protection</b></font></A>
<img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}">
<FONT COLOR="#006666"><b>Virgenere Encryption</b></font></font>
<BR>
<BR>
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td><font FACE="helvetica,arial,geneva">
<br>
<br>
<!-- Description --><!--content_start-->
A fine example of the classic virgenere script and is nearly impossible to decode, even when using frequency analysis.  This script is also entertaining since you can actually see the encryption taking place.
<hr>
</td></tr>
</table>
<!-- Demonstration -->
<center>
<form name="inputo">
<textarea name=written rows=12 cols=40>Type message to encode here</textarea>
<br>
Code Phrase:<input type=text name=codeWord value="code phrase here">
<input type=button value="Encode" onClick="preTime(codeWord.value,written.value, 0);">
<input type=button value="Decode" onClick="preTime(codeWord.value,written.value, 1);">
</form>
</center>
<P>
<P>
<a name="source">
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td BGCOLOR=yellow><font FACE="helvetica,arial,geneva"><b>JavaScript Source Code 3000:  Password Protection:  Virgenere Encryption</b>
<p>Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s).  The script is yours!!!
<br><br></font></td></tr>
<tr><td BGCOLOR=yellow ALIGN=CENTER>
<form NAME="copy">

<DIV align="center">
<input type=button value="Highlight All" onClick="javascript:this.form.txt.focus();this.form.txt.select();">&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="total" VALUE="Script Size:  2.99 KB" size=24>
</DIV>

<textarea NAME="txt" ROWS=20 COLS=75 WRAP=VIRTUAL>

&lt;!-- TWO STEPS TO INSTALL VIRGENERE ENCRYPTION:

  1.  Copy the coding into the HEAD of your HTML document
  2.  Add the last code into the BODY of your HTML document  --&gt;

&lt;!-- STEP ONE: Paste this code into the HEAD of your HTML document  --&gt;

&lt;HEAD&gt;

&lt;SCRIPT LANGUAGE="JavaScript"&gt;
&lt;!-- Original:  Francisco Ryan Tolmasky (iopossum@mailcity.com) --&gt;
&lt;!-- Web Site:  http://iopossum.tripod.com --&gt;

&lt;! &gt;
&lt;! &gt;

&lt;!-- Begin
var TID = 0;
var longer = 0;
var thirdwrite = "";
var alphabet = new Array("0@","1#","2$","3%","4^","5&","6*","7 = ","8-","9+","Aa","Bb","Cc","Dd","Ee","Ff","Gg","Hh","Ii","Jj","Kk","Ll","Mm","Nn","Oo","Pp","Qq","Rr","Ss","Tt","Uu","Vv","Ww","Xx","Yy","Zz");
function preTime(coco, uinput, question) {
longer = coco.length - 1;
placement = 0;
ref = 0 ;
secondWrite = "";
firstWrite = "";
thirdWrite = "";
code1(coco, uinput, longer, question);
}
function findshift(letter) {
for (i = 0; i &lt; 36; i++) {
if ((alphabet[i].substring(0,1) == letter) || (alphabet[i].substring(1,2) == letter)) {
if (alphabet[i].substring(0,1) == letter) {
x = 0;
}
if (alphabet[i].substring(1,2) == letter) {
x = 1;
}
return i;
      }
   }
}
function check(letter) {
bill = "no";
for (i = 0; i &lt; 36; i++) {
if ((alphabet[i].substring(0,1) == letter) || (alphabet[i].substring(1,2) == letter)) {
bill = "yes";
   }
}
if (bill == "yes") {
return true;
}
else {
return false;
   }
}
function fixoffset(takin) {
if (takin &gt; 35) {
return (takin - 36);
}
else {
return takin;
   }
}
function code1(inval1,inval2,inval3,sage) {
if (check(inval2.charAt(placement))) {
if (check(inval1.charAt(ref))) {
if (sage == 0) { 
shift = findshift(inval1.charAt(ref));
}
if (sage == 1) { 
shift = 36 - findshift(inval1.charAt(ref));
   }
}
else {
shift = 0;
}
orig = findshift(inval2.charAt(placement));
firstWrite = firstWrite+alphabet[fixoffset(orig+shift)].charAt(x);
}
else {
firstWrite = firstWrite+inval2.charAt(placement);
}
secondWrite = inval2.substring(placement+1,inval2.length+1);
thirdWrite = firstWrite+secondWrite;
document.inputo.written.value = thirdWrite;
placement++;
if (ref == inval3) {
ref = 0
}
else {
ref++;
}
if (placement == (inval2.length)) {
window.clearTimeout(TID);
return false;
}
one = inval1;
two = inval2;
three = inval3;
goer = sage;
TID = window.setTimeout("code1(one, two, three, goer)", 0);
}
//  End --&gt;
&lt;/script&gt;
&lt;/HEAD&gt;

&lt;!-- STEP TWO: Copy this code into the BODY of your HTML document  --&gt;

&lt;BODY&gt;

&lt;center&gt;
&lt;form name="inputo"&gt;
&lt;textarea name=written rows=12 cols=40&gt;Type message to encode here&lt;/textarea&gt;
&lt;br&gt;
Code Phrase:&lt;input type=text name=codeWord value="code phrase here"&gt;
&lt;input type=button value="Encode" onClick="preTime(codeWord.value,written.value, 0);"&gt;
&lt;input type=button value="Decode" onClick="preTime(codeWord.value,written.value, 1);"&gt;
&lt;/form&gt;
&lt;/center&gt;

 

&lt;!-- Script Size:  2.99 KB --&gt;</textarea><br><font FACE="helvetica,arial,geneva"></font></td></tr>

</table>
</form>
</FONT>
</CENTER>


</center>
</body></html>
